Page({
  data: {
    isShowSecond: true,
    // isShowLogin: false
  },
  onLoad() {
    var openId = my.getStorageSync({
      key: "openId"
    }).data
    if (openId && openId.length > 0) {  
      my.reLaunch({
        url:"/pages/index/index"
      })
    }
  },
  openClick() {
    my.openCardList({
      success: (res) => {
        console.log("调用成功", res);
      },
      fail: (error) => {
        console.log("调用失败", error);
      },
    });
  },
  joinClick() {

    // var url="https://memberprod.alipay.com/account/openform/activecard.htm?app_id=2021003181621354&template_id=20240526000000005300431000300945&__webview_options__=canPullDown=NO&transparentTitle=auto"
    // my.ap.openURL({
    //   url: url, // 请将 url 替换为有效的页面地址
    //   success: (res) => {
    //     console.log('openURL success', res)
    //   },
    //   fail: (err) => {
    //     console.log('openURL success', err)
    //   }
    // });
    var that = this


    var url = "https://memberprod.alipay.com/account/openform/activecard.htm?app_id=2021003181621354&template_id=20240526000000005300431000300945&__webview_options__=canPullDown=NO&transparentTitle=auto"
    my.addCardAuth({
      url: url,
      success: (res) => {
        console.log(res)
        console.log(res.result.request_id)

        my.request({
          url: "https://xg.app365.cn/payment/alipayNotify",
          data: res.result,
          method: "POST",
          success: (res) => {
            my.alert({
              content: '领取成功'
            });
            console.log(res)
            if (res && res.status == 200) {
              my.setStorageSync({
                key: "openId",
                data: res.data.data.open_id
              })
            }
            my.reLaunch({
              url: '../index/index'
            });
            // this.openClick()
          },
          fail: (res) => {
            my.alert({
              content: '领取失败'
            });
          },
        })

      },
      fail: (res) => {
        my.alert({
          content: '领取失败'
        });
      },
    });
    // this.setData({ 
    //   isShowSecond: false,
    //   isShowLogin: true
    // })
  },

  
  getPhoneNumber() {
    my.getPhoneNumber({
      success: (res) => {
        let encryptedData = res.response;
        console.log(encryptedData);
        my.getAuthCode({
          success: (res) => {
            debugger
          }
        })
        // my.getSetting({
        //   success:(res) =>{
        //     debugger
        //     console.log(res)
        //   }
        // });
        // my.request({
        //   //你的服务器地址
        //   url: 'https://xxxxxxx',
        //   data: encryptedData,
        // });
        my.navigateTo({
          url: '../index/index'
        });
      },
      fail: (res) => {
        console.log(res);
      },
    });
  }
});